﻿using System;
using System.Collections.Generic;

using System.Text;
using RoughJs.Ast;

namespace RoughJs.Error
{
    public class WrappedException : EvaluatorException
    {
        /**
     * @see Context#throwAsScriptRuntimeEx(Throwable e)
     */
        public WrappedException(Exception exception):base("Wrapped " + exception.ToString())
        {
            
            this.exception = exception;
            Kit.initCause(this, exception);

            int[] linep = { 0 };
            String sourceName = Context.getSourcePositionFromStack(linep);
            int lineNumber = linep[0];
            if (sourceName != null)
            {
                initSourceName(sourceName);
            }
            if (lineNumber != 0)
            {
                initLineNumber(lineNumber);
            }
        }

        /**
     * Get the wrapped exception.
     *
     * @return the exception that was presented as a argument to the
     *         constructor when this object was created
     */
        public Exception getWrappedException()
        {
            return exception;
        }

        /**
         * @deprecated Use {@link #getWrappedException()} instead.
         */
        public Object unwrap()
        {
            return getWrappedException();
        }

        private Exception exception;
    }
}
